package com.zyzd.baseprojectofvolly.utils;

import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.os.Environment;

import java.io.File;

/**
 * Created by LZY on 2017/6/30.
 */

public class FileUtils {
    public static  File getHxBasePath(Context context, String currentUsername, String tochatName) {
        String easemob_appkey;
        try {
            ApplicationInfo applicationInfo = context.getPackageManager().getApplicationInfo(context.getPackageName(), PackageManager.GET_META_DATA);
            Bundle metaData = applicationInfo.metaData;

            easemob_appkey = metaData.getString("EASEMOB_APPKEY");
        } catch (PackageManager.NameNotFoundException e) {
            easemob_appkey = "1149170313178454#zml";
            e.printStackTrace();
        }

        File file = new File(Environment.getExternalStorageDirectory(), "Android/data/" + context.getPackageName() + "/" + easemob_appkey + "/files/" + currentUsername + "/" + tochatName);
        if (!file.exists()) {
            file.mkdirs();
        }
        return file;
    }

    public static  File getHxFile(Context context, String currentUsername, String tochatName, String remoteUrl) {
        return new File(getHxBasePath(context, currentUsername, tochatName), remoteUrl.substring(remoteUrl.lastIndexOf("/") + 1));
    }
}
